package com.extension.company.presenter.home;

import com.extension.company.common.mvp.BasePresenter;
import com.extension.company.contract.home.GoodInfoFragmentContract;
import com.extension.company.model.entity.GoodsInfoDetail2;
import com.extension.company.model.entity.GoodsInforBean;
import com.extension.company.model.home.GoodsInfoFragmentMode;

/**
 * 作者：zwk
 * 时间：on 2019/2/19 13:51
 * 功能：商品详情的P层
 */
public class GoodInfoFragmentPresenter extends BasePresenter<GoodInfoFragmentContract.Mode, GoodInfoFragmentContract.View> {
	@Override
	public GoodInfoFragmentContract.Mode createModel() {
		return new GoodsInfoFragmentMode();
	}

	@Override
	protected void onViewDestroy() {

	}

	/**
	 * 商品详情和商品评论的网络请求
	 *
	 * @param goods_id 商品的id
	 */
	public void goodsAndCommitRequest(int goods_id) {
		model.goodsAndCommitRequest(goods_id, new GoodInfoFragmentContract.M2P() {
			@Override
			public void m2pSuccess(GoodsInforBean goodsInforBean) { // 请求成功
				if (null != goodsInforBean.getData().getGoods_info()) {
					if (null != getView()) {
						String images = goodsInforBean.getData().getGoods_info().getImages(); // 获取banner图网址
						String[] imgeArray = images.split(",");
						getView().banner(java.util.Arrays.asList(imgeArray));  // 回调banner 页码
						getView().goodsInfo(goodsInforBean.getData().getGoods_info()); // 回调数据

						// 处理具体的规格
					}
				}
			}

			@Override
			public void m2pFaile() { // 请求失败
			}

			@Override
			public void m2p(GoodsInfoDetail2 bean2) {
				getView().p2v(bean2);

			}
		});

	}

	/**
	 * 添加商品到购物车
	 */
	public void addGoods2Cart(String goodId, String goodsNum, String goodSkuId) {
		model.addCart(goodId, goodsNum, goodSkuId, new GoodInfoFragmentContract.addM2P() {
			@Override
			public void addGoods2Cart(String msg) { // 添加后，返回的msg
				if (null != getView()) {
					getView().addCarMsgCallBack(msg);
				}
			}
		});
	}
}
